package com.qing.springcloud.controller;

import com.qing.springcloud.annotation.RequireLogin;
import com.qing.springcloud.annotation.ResponseResult;
import com.qing.springcloud.dto.group.ChatGroupDTO;
import com.qing.springcloud.dto.group.GroupApplicationHandleDTO;
import com.qing.springcloud.dto.group.GroupCreateDTO;
import com.qing.springcloud.dto.group.GroupMemberDTO;
import com.qing.springcloud.service.ChatGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author caozhipeng
 * @date 2025/7/21
 */
@RestController
@RequestMapping("/group")
@ResponseResult
@RequireLogin
public class ChatGroupController {

    @Autowired
    private ChatGroupService groupService;

    //   创建群聊
    @PostMapping("/createGroup")
    public ChatGroupDTO createGroup(@RequestBody GroupCreateDTO dto){
        return groupService.createGroup(dto);
    }
    //    申请加入群聊
    @PostMapping("/joinGroup")
    public void joinGroup(@RequestParam("userId") Long userId, @RequestParam("groupId") Long groupId, @RequestParam("message") String message){
        groupService.joinGroup(userId, groupId, message);
    }
    //    处理群聊加入申请
    @PostMapping("/handleGroupJoinRequest")
    public void handleGroupJoinRequest(@RequestBody GroupApplicationHandleDTO dto){
        groupService.handleGroupJoinRequest(dto);
    }
    //    退群
    @PostMapping("/leaveGroup")
    public void leaveGroup( @RequestParam("userId") Long userId, @RequestParam("groupId") Long groupId){
        groupService.leaveGroup(userId, groupId);
    }
    //    将成员移除群聊-踢人
    @PostMapping("/kickGroupMember")
    public void kickGroupMember( @RequestParam("operatorId") Long operatorId, @RequestParam("groupId") Long groupId, @RequestParam("userId") Long userId){
        groupService.kickGroupMember(operatorId, groupId, userId);
    }

    //    获取群消息
    @GetMapping("/getGroupMembers")
    public List<GroupMemberDTO> getGroupMembers( @RequestParam("groupId") Long groupId){
        return groupService.getGroupMembers(groupId);
    }

}
